<template>
  <div>
    <el-dialog :visible.sync="detailVisible" width="60%">
    <!--dialog项目评价弹窗-->
    <quotationConfirm
      class="tableComponent"
      :quotationConfirm="quotationConfirm"
    />
    <quotationConfirm class="tableComponent" :quotationConfirm="price" />
    <simpleTable :simpleTableData="simpleTableData"></simpleTable>
    <!--评分扣分具体事项-->
    <div class="score-wrap">
        <el-row class="time-wrap">
          <el-col :span="12" class="begin-time" style="marginRight: 280px">
            <label>项目开始时间：</label>
            <span>{{currentDetail.projectStartTime}}</span>
          </el-col>
          <el-col :span="12">
            <label>项目结束时间：</label>
            <span>{{currentDetail.projectEndTime}}</span>
          </el-col>
        </el-row>
        <div>
          <el-row class="cash-end">
            <el-col :span="12">
              <label>结算金额（万元）：</label>
              <span>{{currentDetail.settleAmount}}</span>
            </el-col>
            <el-col :span="12" class="right-opt">
              <label>是否正常结束</label>
              <el-radio-group :value="currentDetail.isNormalEnd" disabled>
                <el-radio :label="0">是</el-radio>
                <el-radio :label="1">否</el-radio>
              </el-radio-group>
            </el-col>
          </el-row>
        </div>
        <!--违规扣分-->
        <div class="current-score">
          <span
            >当前扣分值：{{ currentDeductScore() }}分</span
          >
        </div>
        <div class="deduction-wrap">
          <label><i class="must">*</i>违规扣分</label>
          <ul class="remain">
            <li v-for="(item, index) in radioList" :key="index">
              <div class="deduction-title">{{ item.ruleName }}</div>
              <el-radio :value="item.whetherDeduct" label="0" disabled>是</el-radio>
              <el-radio :value="item.whetherDeduct" label="1" disabled>否</el-radio>
            </li>
          </ul>
        </div>
        <div class="deduction-reason-wrap">
          <label>备注：</label>
          <span>{{currentDetail.scoreindexList[0].remark}}</span>
        </div>
      </div>
  </el-dialog>
      <el-dialog title="单位详情" :visible.sync="detailDialogVisible" width="60%"
      ><quotationConfirm :quotationConfirm="unitInfo"></quotationConfirm
    ></el-dialog>
  </div>
</template>

<script>
import quotationConfirm from "@/common/operation/quotationConfirm";
import simpleTable from "@/common/operation/simpleTable";
import {
  getExtractArticle,
  getScore
} from "@/api/unit/extract.js";
import { getUnit } from "@/api/unit/unit.js";

export default {
  components: {
    quotationConfirm,
    simpleTable
  },
  props: ["projectVisible", "currentDetail"],
  created() {
    getScore().then((res) => {
        this.radioList = res.rows;
        this.radioList?.forEach((item) => {
          if (item.whetherDeduct === null) {
            item.whetherDeduct = "0";
          }
        });
      });
  },
  data() {
    return {
      simpleTableData: {
        title: ["单位名称", "状态", "报价金额（元）", "抽取时间", "操作"],
        list: [],
      },
      saveData: {
        fileUrl: [],
        endDate: "", // 选择日期
        deductReason: "", // 扣分原因
        radioList: [],
      },
      currentRow: [],
      unitInfo: [
        {
          name: "单位序号",
          detailInfo: "1",
          showTwo: false,
          require: false,
        },
        {
          name: "单位类型",
          detailInfo: "1",
          showTwo: false,
        },
        {
          name: "单位名称",
          detailInfo: "1",
          showTwo: false,
        },
        {
          name: "资质等级",
          detailInfo: "1",
          showTwo: false,
        },
        {
          name: "资质范围",
          detailInfo: "1",
          showTwo: false,
        },
        {
          name: "注册地址",
          detailInfo: "重庆市九龙坡区金凤街道",
          showTwo: false,
        },
        {
          name: "备注",
          detailInfo: "1",
          showTwo: false,
        },
      ],
      detailDialogVisible: false
    }
  },
  methods: {
    currentDeductScore() {
      let deduct = 0;
      this.currentDetail.scoreindexList.forEach((item) => {
        if (item.whetherDeduct === "1") {
          deduct += 2;
        }
      });
      return deduct;
    },
    handleRandomBan(val) {
      switch (val) {
        case "0":
          return "正常";
        case "1":
          return "排除";
        case "2":
          return "中签";
        case "3":
          return "中标";
        case "4":
          return "未中标";
        case "5":
          return "废除报价";
      }
    },
  },
  computed: {
    detailVisible: {
      get() {
        return this.projectVisible;
      },
      set(value) {
        this.$emit("update:projectVisible", value);
      },
    },
    quotationConfirm() {
      const currentDetail = this.currentDetail;
      this.radioList?.forEach((item, index) => item.whetherDeduct = currentDetail.scoreindexList[index].whetherDeduct);
      getExtractArticle({ randomBan: 3, extractId: currentDetail?.extractId }).then(res => {
        const companyInfo = res.rows;
        for (var i = 0; i < companyInfo.length; i++) {
          const obj = companyInfo[i];
          for (const j in obj) {
            if (obj[j] === null) {
              obj[j] = "";
            } else {
              obj[j] = obj[j];
            }
          }
          companyInfo.forEach((item) => {
        this.simpleTableData.list.push([
          item.randomUnitName,
          this.handleRandomBan(item.randomBan),
          item.bidamount === null ? "" : item.bidamount,
          item.createTime,
          {
            handleTile: "查看详情",
            org: item,
            callBack: (currentRow, index) => {
              // console.log("currentRow",currentRow,"index",index)
              this.currentObj = currentRow[currentRow.length - 1].org;
              this.detailDialogVisible = true;
              // 获取单位详细信息
              getUnit(this.currentObj.randomUnitId).then((res) => {
                // console.log(res)
                const relativeInfo = res.data;
                for (const j in relativeInfo) {
                  if (relativeInfo[j] === null) {
                    relativeInfo[j] = "";
                  } else {
                    relativeInfo[j] = relativeInfo[j];
                  }
                }
                // 传给组件展示的公司信息
                this.unitInfo = [
                  {
                    name: "单位名称",
                    detailInfo: relativeInfo.unitName,
                    showTwo: true,
                  },
                  {
                    name: "组织机构代码",
                    detailInfo: relativeInfo.unitInstitutionId,
                    showTwo: true,
                  },
                  {
                    name: "法定代表人",
                    detailInfo: relativeInfo.unitRepresentative,
                    showTwo: true,
                  },
                  {
                    name: "法定代表人联系电话",
                    detailInfo: relativeInfo.unitRepresentativePhone,
                    showTwo: true,
                  },
                  {
                    name: "联系人",
                    detailInfo: relativeInfo.unitLinkman,
                    showTwo: true,
                  },
                  {
                    name: "联系电话",
                    detailInfo: relativeInfo.unitPhone,
                    showTwo: true,
                  },
                  {
                    name: "单位序号",
                    detailInfo: relativeInfo.unitSort,
                    showTwo: true,
                  },
                  {
                    name: "资质等级",
                    detailInfo: relativeInfo.unitNaturalGrade,
                    showTwo: true,
                  },
                  {
                    name: "资质范围",
                    detailInfo: relativeInfo.unitNaturalScope,
                    showTwo: true,
                  },
                  {
                    name: "注册地址",
                    detailInfo: relativeInfo.unitAddress,
                  },
                  {
                    name: "备注",
                    detailInfo: relativeInfo.unitRemarks,
                  },
                ];
              });
            },
          },
        ]);
        for (var i = 0; i < this.simpleTableData.list.length; i++) {
          if (i >= 1) {
            this.simpleTableData.list.splice(0, 1);
          }
        }
      });
        }
      })
      return [
      {
          name: "申请单位",
          detailInfo: currentDetail.createBy,
          showTwo: true,
        },
        {
          name: "项目名称",
          detailInfo: currentDetail.extractItem,
          showTwo: true,
        },
        {
          name: "建设地址",
          detailInfo: currentDetail.extractAddress,
          showTwo: true,
        },
        {
          name: "建设周期",
          detailInfo: currentDetail.extractPeriod,
          showTwo: true,
        },
        {
          name: "工程费用（万元）",
          detailInfo: currentDetail.extractPrice,
          showTwo: true,
        },
        {
          name: "工程概况",
          detailInfo: currentDetail.projectOverview,
          showTwo: true,
        },
    ]
    },
    price() {
      const currentRow = this.currentDetail;
      return [
          {
            name: "中介机构服务费（万元）",
            detailInfo: currentRow.maxPrice,
            showTwo: true,
          },
          {
            name: "抽取要求",
            detailInfo: currentRow.extractBanReason, //不确定
            showTwo: true,
          },
          {
            name: "经办人",
            detailInfo: currentRow.extractCharge,
            showTwo: true,
          },
          {
            name: "联系电话",
            detailInfo: currentRow.extractPhone,
            showTwo: true,
          },
          {
            name: "抽  取  人",
            detailInfo: currentRow.extractUser,
            showTwo: true,
          },
          {
            name: "抽取地点",
            detailInfo: currentRow.extractPlace,
            showTwo: true,
          },
          {
            name: "抽取时间",
            detailInfo: currentRow.tenderStartTime,
            showTwo: true,
          },
          {
            name: "抽  取  库",
            detailInfo: currentRow.unitTypeName,
            showTwo: true,
          },
          {
            name: "业务类型",
            detailInfo: currentRow.extractBusinessType,
            showTwo: true,
          },
          {
            name: "签字表",
            detailInfo: currentRow.extractSignUrl,
            showimg: true,
            showTwo: true,
          },
          {
            name: "是否需要驻场服务",
            detailInfo: currentRow.extractResident == 0 ? "是" : "否",
            showTwo: false,
          },
          {
            name: "驻场服务人数(至少)",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractResidentNumber
                : "",
            showTwo: true,
          },
          {
            name: "完成时限",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractLimitedTime
                : "",
            showTwo: true,
          },
          {
            name: "驻 场 要 求",
            detailInfo:
              currentRow.extractResident == 0
                ? currentRow.extractStationRequire
                : "",
            showTwo: false,
          },
          {
            name: "抽取单位数",
            detailInfo: currentRow.extractNumber,
            showTwo: false,
          },
        ]
    }
  },
};
</script>

<style scoped lang="scss">
.must {
  color: red;
  margin-right: 5px;
}
.current-score {
  color: #da0620;
  padding-left: 140px;
  font-size: 18px;
  font-weight: 600;
  margin-top: 20px;
}
.bigfont {
  font-size: 19px;
  font-weight: 100;
  text-align: center;
  font-family: FangSong;
}
.small {
  text-align: center;
  font-weight: 100;
  font-size: 16px;
}
.fontitem1 {
  vertical-align: top;
  font-size: 16px;
  font-weight: 100;
}
.fontitem12 {
  font-size: 16px;
}
.topfont {
  font-size: 16px;
  font-weight: 400;
}
.input {
  font-size: 18px;
  font-weight: 400;
}
.small1 {
  text-align: center;
  font-weight: 100;
  font-size: 20px;
}
.zhong {
  font-size: 16px;
  padding-left: 10px;
}
.form-img-out {
  width: 130px;
  height: 130px;
}
.form-img-line {
  width: 500px;
  height: 500px;
}
.form-dialog {
  text-align: center;
}
.topfont {
  font-size: 16px;
  font-weight: 400;
}
.project-name {
  font-family: FangSong;
}
.project-name-1 {
  font-family: FangSong;
}
.topfont-name {
  font-family: FangSong;
}
.font-family {
  font-family: FangSong;
}
.printTable {
  border: unset;
}
.noBorder {
  border: unset;
}
.rightBorder {
  border-right: 1px solid #9a9a9a;
}
.bottomBorder {
  border-bottom: 1px solid #9a9a9a;
}
.title {
  margin-bottom: 30px;
  font-size: 24px;
  font-family: SimSun;
}
.calc-cash {
  width: 220px;
  input {
    width: 100%;
  }
}
.cash-end {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  margin-left: 3px;
  .right-opt {
    position: relative;
    right: 13px;
    align-self: center;
    text-align: center;
  }
}
.score-wrap {
  padding: 15px;
  display: flex;
  flex-direction: column;
  label {
    width: 110px;
    text-align: right;
  }
  .time-wrap {
    display: flex;
    width: 88%;
    justify-content: space-between;
    padding-bottom: 20px;
    .begin-time,
    .end-time {
      display: flex;
      align-items: center;
      flex-wrap: wrap;
      ::v-deep .el-input__inner {
        padding: 10px;
      }
    }
    .begin-time {
      margin-left: 20px;
    }
  }
  .deduction-wrap {
    display: flex;
    align-items: baseline;
    > ul {
      li {
        list-style: none;
        display: flex;
        padding: 5px 0;
        > .deduction-title {
          width: 50%;
        }
      }
    }
  }
  .deduction-reason-wrap {
    display: flex;
    > textarea {
      width: 80%;
    }
  }
}
.remain {
  width: calc(100% - 100px);
}
</style>